<template>
  <div class="my-list">
    <div class="xyd-container">
      <div class="xyd-c-title clearfix">
        <a href="javascript:;" v-if="home" title="推荐" :style="width" @click="index = 1">
          <i :class="index === 1 ? 'xyd-home_a' : 'xyd-home'" ></i>
        </a>
        <a href="javascript:;" title="历史" :style="width" @click="index = 2">
          <i :class="index === 2 ? 'xyd-history_a' : 'xyd-history'" ></i>
        </a>
        <a href="javascript:;" title="收藏" :style="width" @click="index = 3">
          <i :class="index === 3 ? 'xyd-collection_a' : 'xyd-collection'"></i>
        </a>
        <a href="javascript:;" title="下载" :style="width" @click="index = 4">
          <i :class="index === 4 ? 'xyd-download_a' : 'xyd-download'" ></i>
        </a>
        <a href="javascript:;" title="播单" :style="width" @click="index = 5">
          <i :class="index === 5 ? 'xyd-play_a' : 'xyd-play'" ></i>
        </a>
      </div>
      <div class="xyd-c-content">
        <ul v-if="index === 1">
          <li v-for="item,i in homeHot" :key="i">
            <a :href="'#/resource/preview/'+item.id">{{item.title}}</a>
          </li>
        </ul>
        <ul v-if="index === 2">
          <li v-for="item,i in history" :key="i">
            <a :href="'#/resource/preview/'+item.id">{{item.title}}</a>
          </li>
        </ul>
        <ul v-if="index === 3">
          <li v-for= "item,i in collection" :key="i">
            <a :title="item.resource_name" :href="'#/resource/download/' + item.id">{{item.resource_name}}</a>
          </li>
        </ul>
        <ul v-if="index === 4">
          <li v-for="item,i in download" :key="i">
            <a :title="item.resource_name" :href="'#/resource/download/' + item.id">{{item.title}}</a>
          </li>
        </ul>
        <ul v-if="index === 5">
          <li v-for="item,i in playList" :key="i">
            我的播单todo
          </li>
        </ul>
      </div>
    </div>
  </div>
</template>

<script>
import { getCollection } from 'api/common'
import { getPlayList, getHistory, getDownload } from 'api/user'

export default {
  name: 'myList',
  props: {
    home: {
      type: Boolean,
      default: false
    },
    homeHot: {
      type: Array
    }
  },
  data() {
    return {
      index: 1,
      history: [],
      collection: [],
      download: [],
      playList: [],
      width: this.home ? 'width:20%;' : 'width:25%;'
    };
  },
  created() {
    // 收藏
    this.index = this.home ? 1 : 2
    getCollection()
    .then(res => {
      this.collection = res.collection
    })
    .catch(err => console.log(err))
    // 播单
    getPlayList()
    .then(res => {
      console.log(res)
      this.playList = res.data
    })
    .catch(err => console.log(err))
    // 历史
    getHistory()
    .then(res => {
      this.history = res.data
    })
    .catch(err => console.log(err))
    // 下载
    getDownload()
    .then(res => {
      this.download = res.data.resource
    })
    .catch(err => console.log(err))
  },
  methods: {

  }
};
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
.my-list{
  .xyd-container{
    border: none;
    .xyd-c-title{
      border: none;
      >a{
        float: left;
        display: inline-block;
        // padding: 0 15px;
      }
    }
  }
  .xyd-c-content{
    >ul{
      padding: 15px;
      height: 430px;
      >li{
        width: 100%;
        line-height: 40px;
        word-break: break-all;//截断，中文无影响，英文会直接截断，或者用normal
        overflow: hidden;//溢出隐藏
        text-overflow: ellipsis;//省略号
        white-space: nowrap;//不换行
        a{
          &:hover{
            text-decoration: underline;
            color: #00A2EA;
          }
        }
      }
    }
  }
}
</style>